package com.nacos.novelcommon.util;

import lombok.Data;

import java.io.Serializable;

/**
 * 返回结果同意封装
 *
 * @author zy 刘会发
 * @since 2020/4/2
 */
@Data
public class Result<T> implements Serializable {
    private static final long serialVersionUID = -533989960257435515L;
    private Integer code;
    private T obj;
    private String mes;

    private Result(Integer code, T obj, String mes) {
        this.code = code;
        this.obj = obj;
        this.mes = mes;
    }

    public static <T> Result<T> success(T obj) {
        return new Result<>(2000, obj, "请求成功");
    }

    public static <T> Result<T> success(Integer code, T obj) {
        return new Result<>(code, obj, "请求成功");
    }

    public static <T> Result<T> success(Integer code, T obj, String mes) {
        return new Result<>(code, obj, mes);
    }

    public static <T> Result<T> failed() {
        return new Result<>(5000, null, "请求失败");
    }

    public static <T> Result<T> failed(Integer code, String mes) {
        return new Result<>(code, null, mes);
    }

    public static <T> Result<T> failed(Integer code, T obj, String mes) {
        return new Result<>(code, obj, mes);
    }
}
